<%@ page import="com.guotd.ticketSystem.entity.Flight" %>
<%@ page import="java.util.List" %>
<%@page pageEncoding="UTF-8" contentType="text/html; UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>航班列表</title>
    <link rel="stylesheet" href="css/list2.css">
    <script>
        function confirmDelete() {
            return confirm('您确定要删除这个航班吗？客舱信息和订单信息将一并被删除，请谨慎选择！！！');
        }
    </script>
</head>
<body>
<%
    if (session.getAttribute("flight_msg") != null)
    {
%>
<div class="message"><%= session.getAttribute("flight_msg") %></div>
<%
    }
%>
<%int type = (int) session.getAttribute("type"); %>
<% List<Flight> flights = (List<Flight>) request.getAttribute("flights");%>
<% if (type==2)
{
%>
<a href="flight_add.jsp" class="table-button">添加航班信息</a>
<a href="index_admin.jsp" class="table-button">回到主页</a>
<%
    }
%>
<% if (type==1)
{
%>
<a href="index_user.jsp" class="table-button">回到主页</a>
<%
    }
%>
<table>
    <tr>
        <th>航班名</th>
        <th>机型</th>
        <th>起始站</th>
        <th>起飞日期</th>
        <th>起飞时间</th>
        <th>抵达站</th>
        <th>抵达日期</th>
        <th>抵达时间</th>
        <th colspan="4">操作</th>
    </tr>
    <%
        if(flights!=null){
            for (Flight f : flights) {
    %>
    <tr>
        <td> <%=f.getName()%> </td>
        <td> <%=f.getPlane().getType()%> </td>
        <td> <%=f.getAirline().getFromAirport()%> </td>
        <td> <%=f.getSchedule().getFromDate()%> </td>
        <td> <%=f.getSchedule().getFromTime()%> </td>
        <td> <%=f.getAirline().getToAirport()%> </td>
        <td> <%=f.getSchedule().getToDate()%> </td>
        <td> <%=f.getSchedule().getToTime()%> </td>
        <td> <a href="getCabins?flightId=<%=f.getId()%>" class="table-button">查看客舱信息</a> </td>
        <% if (type==2)
             {
        %>
        <td> <a href="getOrders?flightId=<%=f.getId()%>" class="table-button">查看订单信息</a> </td>
        <td> <a href="flight_edit.jsp?id=<%=f.getId()%>&&name=<%=f.getName()%>&&planeId=<%=f.getPlane().getId()%>&&airlineId=<%=f.getAirline().getId()%>&&scheduleId=<%=f.getSchedule().getId()%>" class="table-button">编辑</a> </td>
        <td> <a href="delFlight?id=<%=f.getId()%>" class="table-button" onclick="return confirmDelete();">删除</a> </td>
    </tr>
         <%
             }
         %>
    <%
            }
        }
    %>
</table>
</body>
</html>